package base.thread.state.stop;

/**
 * @Author: my_code
 * @Create: 2020-12-07 18:58
 */
public class StopTest implements Runnable{

    private static boolean flag;

    public static void main(String[] args) {
        new Thread(new StopTest()).start();
        for (int i = 0; i < 10; i++) {
            if (i==9){
                flag = stop();
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    //自定义stop方法停掉线程
    private static boolean stop() {
        return true;
    }

    @Override
    public void run() {
        while (true){
            System.out.print(".");
            if (flag){
                System.out.println("线程结束");
                break;
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
